﻿	jQuery.fn.extend( {
  outerHTML: function( replacement )
  {
    if (replacement)
    {
      return this.each(function (){ $(this).replaceWith(replacement); });
    }
    var tmp_node = $("<div></div>").append( $(this).clone() );
    var markup = tmp_node.html();
    tmp_node.remove();
    return markup;
  }
});
	
	function CountListQuantity(type)
	{
		jQuery.ajax({
                type: "get",
                url: "countlist.do?type="+type,
                dataType: "html",
                success: function(data, textStatus) {
                },
                error: function() {
                    alert("error");
                }
            });	

	}
	
	function SetListCss()
	{
		$(".list-item").removeClass("alt");
		$(".list-item:odd").addClass("alt");
	}
	
	function ChangeStar()
	{
		
	}
	function GetSequenceByPeople()
	{
		templist = "";
		for (i = 0;i<peoplesequence.length;i++)
		{
			tempitem = $('#item'+peoplesequence[i]).outerHTML();
			if ($('#item'+peoplesequence[i] + ' .div-score .tips').html() == "打分后显示平均分")	
			{
				$('#item'+peoplesequence[i] + ' .div-score').html($('#item'+peoplesequence[i] + ' .div-score-back').html());
				$('#item'+peoplesequence[i] + ' .div-score-back').removeClass("div-score-back").addClass("div-score");
				$('#item'+peoplesequence[i] + ' .div-score .star-back').removeClass("star-back").addClass("star");
				$('#item'+peoplesequence[i] + ' .div-score .star').rating();
			}
			else 
			{
				tempscore = $('#item'+peoplesequence[i] + ' .div-score .score').html();
				tempavgscore = $('#item'+peoplesequence[i] + ' .div-score .tips').html();
				$('#item'+peoplesequence[i] + ' .div-score').html($('#item'+peoplesequence[i] + ' .div-score-back').html());
				$('#item'+peoplesequence[i] + ' .div-score-back').removeClass("div-score-back").addClass("div-score");
				$('#item'+peoplesequence[i] + ' .star-back').removeClass("star-back").addClass("star");
				$('#item'+peoplesequence[i] + ' .div-score .star').rating('select',tempscore);
				$('#item'+peoplesequence[i] + ' .div-score .star').rating('readOnly',true);
				$('#item'+peoplesequence[i] + ' .div-score .score').html(tempscore);
				$('#item'+peoplesequence[i] + ' .div-score .tips').html(tempavgscore);

				
				
			}
			templist = templist + tempitem;
			
		}
		$("#deals-list").html(templist);
		$(".select-sequence").removeClass("current-sequence");
		$("#select-people").addClass("current-sequence");
		SetListCss();
		CountListQuantity(1);
		$('input.star').rating();
		void(0);
	}
	function GetSequenceByPrice()
	{
		templist = "";
		for (i = 0;i<pricesequence.length;i++)
		{
			templist = templist + $('#item'+pricesequence[i]).outerHTML();
		}
		$("#deals-list").html(templist);
		$(".select-sequence").removeClass("current-sequence");
		$("#select-price").addClass("current-sequence");
		SetListCss();
		CountListQuantity(2);
		$('input.star').rating();
		void(0);
	}
	function GetSequenceByDiscount()
	{
		templist = "";
		for (i = 0;i<discountsequence.length;i++)
		{
			templist = templist + $('#item'+discountsequence[i]).outerHTML();
		}
		$("#deals-list").html(templist);
		$(".select-sequence").removeClass("current-sequence");
		$("#select-discount").addClass("current-sequence");
		SetListCss();
		CountListQuantity(3);
		$('input.star').rating();
		void(0);
	}
	
	function CheckEmail(id,formid)
	{
		var search_str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
       var email_val = $("#"+id).val();
       if(search_str.test(email_val)){
			$("form[id=" + formid + "]").submit();
       }else{
        alert("Email格式不正确");
        return 0;
       }
	}
	
	function GotoSearch(keyword)
	{
		window.location.href='index.do?method=search&q='+keyword;
	}